package com.example.hssmgs.Student;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.hssmgs.MainActivity;
import androidx.annotation.Nullable;

import com.example.hssmgs.R;

public class new_info extends Activity {
    Button revise_bt;
    Button back_bt;
    EditText change_account;
    EditText change_id;

    SQLiteDatabase db;
    String student_account;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.new_info);

        InitView();

        // 获取用户信息
        final Intent about_me_intent = getIntent();
        student_account = about_me_intent.getStringExtra("student_id");

        change_account=findViewById(R.id.input_account_tv);
        change_id=findViewById(R.id.input_id_tv);

        //初始化数据库对象
        CommonDatabase commonDatabase = new CommonDatabase();
        db = commonDatabase.getSqliteObject(new_info.this,"test_db");

        revise_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ContentValues values = new ContentValues();
                values.put("id",change_id.getText().toString());

                db.update("student_db", values, "account=?", new String[]{student_account});

                Toast toast=Toast.makeText(getApplicationContext(),"修改成功",Toast.LENGTH_SHORT);
                toast.show();
                finish();
            }
        });

        back_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void InitView() {
        revise_bt=findViewById(R.id.revise_bt);
        back_bt=findViewById(R.id.back_bt);
    }
}
